package com.spark.modules.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spark.modules.system.entity.SysPermission;
import com.spark.modules.system.mapper.SysPermissionMapper;
import com.spark.modules.system.service.ISysPermissionService;
import com.spark.modules.system.utils.RouteConverter;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 系统权限菜单Service
 *
 * @author LYCHEE
 * @date 2025/02/18 14:07
 */
@Service
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, SysPermission> implements ISysPermissionService {

    /**
     * 根据用户ID获取用户菜单
     *
     * @param userId 用户ID
     * @return 菜单数据
     */
    @Override
    public List<Map<String, Object>> selectMenuTreeByUserId(String userId) {
        List<SysPermission> sysPermissions = baseMapper.selectMenuTreeByUserId(userId);
        //return MenuBuilder.buildMenuTree(sysPermissions);
        RouteConverter routeConverter = new RouteConverter();
        return routeConverter.convertToRouteTree(sysPermissions);
    }

    /**
     * 获取用户的权限编码
     *
     * @param userId 用户ID
     * @return 权限编码
     */
    @Override
    public List<String> getAccessCodes(String userId) {
        return baseMapper.getAccessCodes(userId);
    }
}
